<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

require("init.php");

$DBC = new db();
$DBC->SELECTDB("guitig");
$DBC2 = new db();
$DBC2->SELECTDB("guitig");



?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<html>
<head>
<title>iCUP - Beheer</title>
<!--<meta http-equiv="X-UA-Compatible" content="IE=8" />-->
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="hourtable.css" />
<link rel="stylesheet" type="text/css" href="Buttons.css" />
<script type="text/javascript" src="funcs.js"></script>
<script type="text/javascript" src="selectivizr.js"></script>
</head>
<body>
<?php



	$week = 52;
	
	$DBC->QUERY("
		SELECT DISTINCT S.id, S.uur, S.dag
		FROM studieuur S, studieuurklas SK
		WHERE SK.studieuur  = S.id
		AND S.week = '$week'
	");
	
	//$resultheader = mysql_query($QUERY);
	//$columns = mysql_numrows($resultheader);


	
?><table cellspacing="0" align="left" valign="top">
	<tr>
		<td colspan="<?php print($DBC->rows); ?>">
			<h1>Week <?php print("$week"); ?>: alle uren</h1>
		</td>
	</tr>
	<tr style="vertical-align: top;">
<?php

	
	
	$headersdata = $DBC->RESULTS(array("dag", "uur", "id"));

	for($i = 0; $i < $DBC->rows; $i++)
	{
		$headerdata = $headersdata[$i];
		
		$header = $headerdata["dag"] . $headerdata["uur"]; //mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
		$sid = $headerdata["id"];
		
		$DBC2->QUERY("
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
				WHERE studieuur = $sid
			)
			ORDER BY lokaal ASC, vak ASC, docentid ASC
		");
			
				
		
?>		<td>
			<table id="<?php $rnd = mt_rand(10, 99); print($rnd); ?>" cellspacing="0" align="left" valign="top" class="hourtable">
				<tr>
					<th class="uur" colspan="4">
						<?php print($header); ?> 
					</th>
				</tr>
<?php



		for($j=0; $j < $DBC2->rows; $j++)
		{
			$plaatsnr = $DBC2->RESULT("plaatsnr", $j);
			$datavak = $DBC2->RESULT("vak", $j);
			$datadocentid = $DBC2->RESULT("docentid", $j);
			$datalokaal = $DBC2->RESULT("lokaal", $j);



?>				<tr>
					<td id="<?php print($i . $j); ?>">
						<?php print($datavak); ?>
					</td>
					<td>
						<?php print($datadocentid); ?>
					</td>
					<td>
						<?php print($datalokaal); ?>
					</td>
					<td>
						<a class="actionbutton" onclick="delplacefromweek('<?php print("$sid"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/delweek.png" /></a>
					</td>
				</tr>
<?php


		}
		
		
?>				<tr>
					<td colspan="3" style="border-top: 2px solid black; border-right: 2px solid black; width: 100px !important;">
						voeg uur toe...
					</td>
					<td style="border-top: 2px solid black; width: 20px !important;">
						<a onclick="document.getElementById('adder_<?php print($header); ?>').style.display = document.getElementById('choser_<?php print($header); ?>').style.display = (document.getElementById('choser_<?php print($header); ?>').style.display == 'table-row') ? 'none' : 'table-row'; document.getElementById('choosebtn_<?php print($header); ?>').src = (document.getElementById('choser_<?php print($header); ?>').style.display == 'table-row') ? 'pics/exphider.png' : 'pics/expchoser.png';" class="actionbutton"><img src="pics/expchoser.png" id="choosebtn_<?php print($header); ?>" /></a>
					</td>
				</tr>
				<tr style="display: none;" id="adder_<?php print($header); ?>" class="adder">
					<td>
						<input type="text" maxlength="2" id="addHourSubject_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<input type="text" maxlength="3" id="addHourTeacher_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<input type="text" maxlength="3" id="addHourRoomNr_<?php print("$header"); ?>" style="font-size: 12px; margin: 0; padding: 0; width: 90%;" onkeyup="reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');" />
					</td>
					<td>
						<a class="actionbutton" onclick="clearadderfield('<?php print("$header"); ?>'); reloadHoursChoser('<?php print("$header"); ?>', '<?php print("$sid"); ?>');"><input type="image" src="pics/delweek.png" /></a>
					</td>
				</tr>
				<tr style="display: none;" id="choser_<?php print($header); ?>">
					<td colspan="5" style="border-top: 2px solid black;">
<?php



require("gethoursChoser.php");



?>					</td>
				</tr>
			</table>
		</td>
<?php


		
	}
	
	
	
?>	</tr>
</table>
</body>